package jwebtester.security.auth;

import jwebtester.security.hash.Sha512HashFunction;

import org.springframework.security.authentication.encoding.BaseDigestPasswordEncoder;


public class Sha512PasswordEncoder extends BaseDigestPasswordEncoder {

	private transient final Sha512HashFunction hashFunction = new Sha512HashFunction();

	@Override
	public String encodePassword(final String rawPass, final Object salt) {
		final String saltedPass = mergePasswordAndSalt(rawPass, salt, false);
		return hashFunction.calculateHash(saltedPass);
	}

	@Override
	public boolean isPasswordValid(final String encPass, final String rawPass, final Object salt) {
		final String pass2 = encodePassword(rawPass, salt);
		return pass2.equals(encPass);
	}

}
